// pages/reconciliationDetails/reconciliationDetails.js
let app = getApp();
const util = require("../../utils/util.js");
import {
  getOrderDetailApi,
} from "../../api/index.js";
Page({
  /**
   * 页面的初始数据
   */
  data: {
    pageAllHeight: app.globalData.pageAllHeight - 100,
    stopCarList: [],
    parkId: null,
    pageNum: 1,
    pageSize: 10,
    billStatus: null,
    pageFlag: false,
    startTime: null,
    endTime: null,
    zmStatus:null
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(options);
    if (options.item) {
      const item = JSON.parse(options.item);
      const getStartTimeAndEndTime = util.getStartTimeAndEndTime(item.billTime);
      this.setData({
        parkId:item.parkId,
        billStatus:item.billStatus,
        startTime:getStartTimeAndEndTime.startTime,
        endTime:getStartTimeAndEndTime.endTime,
        zmStatus:item.zmStatus
      });
      this.getOrderDetail()
    }
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {},


  //   车费明细
  async getOrderDetail(next) {
    const {
      parkId,
      pageNum,
      pageSize,
      stopCarList,
      startTime,
      endTime,
      zmStatus
    } = this.data;
    const { data: res } = await getOrderDetailApi({
      parkId,
      startTime,
      endTime,
      pageNum: pageNum,
      pageSize,
      zmStatus
    });
    const newStopCarList = next
      ? stopCarList.concat(res.data.records)
      : res.data.records;
    this.setData({
      stopCarList: newStopCarList,
      pageFlag: !res.data.records.length && next,
    });
  },
  
  // 触底事件函数
  scrollToLower(event) {
    const { pageFlag } = this.data;
    if (!pageFlag) {
      this.setData({ pageNum: this.data.pageNum + 1 });
      this.getOrderDetail(true);
    }
  },
  bindChangeTab(e) {
    this.setData({
      // settleHistoryList: [],
      pageNum: 1,
      settledStatus: e.detail.index,
    });
    const { index } = e.detail;
    if (index == 1) {
      // this.getSettledHistory();
    } else {
      // this.getBillList();
    }
  },
});
